package com.sky.controller.admin;

import com.sky.dto.VoucherDTO;
import com.sky.result.Result;
import com.sky.service.VoucherService;
import com.sky.vo.VoucherVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/admin/voucher")
@Api(tags = "优惠券管理")
public class VoucherController {
    @Autowired
    private VoucherService voucherService;

    @PostMapping
    @ApiOperation("新增优惠券")
    public Result<String> add(@RequestBody VoucherDTO dto) {
        voucherService.add(dto);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改优惠券")
    public Result<String> update(@RequestBody VoucherDTO dto) {
        voucherService.update(dto);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除优惠券")
    public Result<String> delete(@PathVariable Long id) {
        voucherService.delete(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("查询优惠券详情")
    public Result<VoucherVO> getById(@PathVariable Long id) {
        return Result.success(voucherService.getById(id));
    }

    @GetMapping("/list")
    @ApiOperation("查询优惠券列表")
    public Result<List<VoucherVO>> list() {
        return Result.success(voucherService.list());
    }
}
